Preserve constant loop bounds through adjoint-lowering#2959
Merged
Conversation
Relocate the forward pass into the same location as the reverse pass, as having the two pieces of the pass in different locations is very confusing. A subdirectory is introduced for the pass for better organization.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2959 +/- ##
==========================================
+ Coverage 96.95% 96.97% +0.02%
==========================================
Files 166 166
Lines 19143 19209 +66
Branches 1772 1788 +16
==========================================
+ Hits 18560 18628 +68
+ Misses 430 429 -1
+ Partials 153 152 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
joeycarter
approved these changes
Jun 19, 2026
joeycarter
left a comment
Contributor
There was a problem hiding this comment.
Looks good, just a few editorial things and questions—nothing blocking. 👍
Co-authored-by: Joey Carter <joey.snarrcarter@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As laid out in #2936, the
--adjoint-loweringpass converts all classical values used by the reverse pass to dynamic ones via a tape caching mechanism (LIFOlist.push/pop). This hinders analyzability for example inqp.specs. This PR skips the tape mechanism for constant loop bounds.As a pre-requisite to implementing the change, the pass is restructured into a more coherent structure (all in the same directory) of pass driver (
AdjointLowering.cpp), forward pass / classical value caching (Forward.cpp), reverse pass / inverse quantum instruction stream & adjoint propagation (Reverse.cpp), and a helper data structure (QuantumCache.cpp/hpp). The actual functional change is very small (2f6ad9e).closes #2936
[sc-122139]
Future improvements: One could apply this fix to any constant classical value cached by the tape.
Additional note: To "fix" the example in the issue one should run the canonicalization pass before the adjoint lowering (standard in our pipeline) so that the detection of constant values is facilitated.